
package com.flowmodule.dao;
import com.flowmodule.bean.*;
import java.sql.*;
import java.util.*;
import util.*;
public class TbFlowDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbFlow tbFlow=null;
    private List<TbFlow> tbFlowList=null;

    public boolean add(TbFlow inTbFlow){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_Flow(FlowName,FlowTypeId,UserId) values(?,?,?)";
        pt = conn.prepareStatement(sql);
        pt.setString(1,inTbFlow.getFlowName());
        pt.setInt(2,inTbFlow.getFlowTypeId());
        pt.setInt(3,inTbFlow.getUserId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inFlowId){
        return UtilDAO.del("Tb_Flow", "FlowId", inFlowId);
    }
    public boolean edit(TbFlow inTbFlow){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_Flow set  FlowName=?,FlowTypeId=?,UserId=?,CreateTime=getdate()  where FlowId=?";
        pt = conn.prepareStatement(sql);
        pt.setString(1,inTbFlow.getFlowName());
        pt.setInt(2,inTbFlow.getFlowTypeId());
        pt.setInt(3,inTbFlow.getUserId());
        pt.setInt(4,inTbFlow.getFlowId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbFlow getTbFlowByFlowId(int inFlowId) {
        tbFlow=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_Flow where FlowId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inFlowId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbFlow == null)tbFlow = getTbFlow(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlow;
    }
    public List<TbFlow> getTbFlowAll() {
        tbFlowList=new ArrayList<TbFlow>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_Flow";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowList.add(getTbFlow(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowList;
    }
    public List<TbFlow> getTbFlowAll(VskPage vp) {
        tbFlowList=new ArrayList<TbFlow>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_Flow";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_Flow", "FlowId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowList.add(getTbFlow(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowList;
    }
    public TbFlow getTbFlow(ResultSet rs) throws Exception{
        TbFlow tbFlow = new TbFlow();
        tbFlow.setFlowId(rs.getInt("FlowId"));
        tbFlow.setFlowName(rs.getString("FlowName"));
        tbFlow.setFlowTypeId(rs.getInt("FlowTypeId"));
        tbFlow.setUserId(rs.getInt("UserId"));
        tbFlow.setCreateTime(rs.getString("CreateTime"));
        return tbFlow;
    }
}
